<?php
class Discommend extends Zend_Db_Table {
	protected $_name = 'cc_discommend';
	private $db;
	
	/**
	 * 折扣推荐信息构造函数
	 * @access public
	 * @return 
	 */
	public function __construct(){
		$this->db = Zend_Db_Table::getDefaultAdapter();
		parent::_setup();
	}
	
	/**
	 * 取前十个推荐折扣信息,用于主页显示
	 * @param int $limit
	 * @return array 折扣信息数组
	 */
	public function getTop($limit) {
		$disSql = 'SELECT  a.*, b.* FROM cc_discommend AS a 
					INNER JOIN cc_discount as b ON a.discid=b.id where a.sdate < curdate() 
					and a.edate > curdate() order by a.power desc limit 0,'.$limit;
		$disRes = $this->getAdapter()->fetchAll ( $disSql );
		return $disRes;
	}
	
	/**
	 * 取所有折扣推荐信息
	 * @access public
	 * @return array 所有折扣推荐信息数组
	 */
	public function getAllDisCommend(){
		$rowset = $this->fetchAll();
		$disCommendArr = $rowset->toArray();
		return $disCommendArr;
	}
	/**
	 * 据折扣ID取折扣信息
	 * @access public
	 * @return array 折扣信息数组
	 */
	public function getDisCommendById($id){
		$where = $this->db->quoteInto("id=?",$id);
		$row = $this->fetchRow($where);
		return $row->toArray();
	}
	/**
	 * 
	 * @access public
	 * @return 
	 */
	public function updCommend($date,$id){
		$where = $this->db->quoteInto("id=?",$id);
		$updCnt = $this->update($date,$where);
		return $updCnt;
	}
	/**
	 * 添加折扣推荐信息
	 * @access public
	 * @return int 返回新增的ID
	 */
	public function insCommend($data){
		$insid = $this->insert($data);
		return $insid;
	}

}
?>